<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<button onclick="submit()">提交</button>
		<script>
			//节流函数-闭包
			// 功能:多次点击按钮无效,只执行一次
			function throttle(fn, delay) {
				let timer = null;
				let flag= false;
				return function() {
					if (flag) {
						return
					}
					flag = true
					fn()
					clearTimeout(timer)
					timer = setTimeout(function() {
						flag = false
					}, delay)
				}
			}
			function fn(){
				console.log('提交')
			}
			submit = throttle(fn,2000)
			
		</script>
	</body>
</html>
